/**
 * @author : cyb1010
 * @date   : 2024-12-26 10:27:03
 * @file   : list.cpp
 */
#include <bits/stdc++.h>
using namespace std;
#define fo(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout)
#define fi first
#define se second
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) int(v.size())
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
void ckmx(int &x, int y) { x < y && (x = y); }
void ckmn(int &x, int y) { x > y && (x = y); }
const int N = 500010;
const ull inf = 1e17;
int __, n, a[N], c, cnt;
ull v, tv, lsx, b[N];
vector<int> t[N], x, ans = {0};
vector<int> upd[N * 2];
unordered_map<int, int> mp;
int main() {
    fo("list");
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i], t[i].resize(a[i]), cnt += a[i];
        for (int &j : t[i]) cin >> j, mp[j]++;
        for (int j = 1; j < a[i]; j++) x.push_back(t[i][j] - t[i][j - 1]);
    }
    sort(ALL(x)), x.erase(unique(ALL(x)), x.end()), cin >> c;
    for (int i = 1; i <= n; i++) cin >> b[i], b[i] += c;
    for (auto [t, c] : mp) tv += c * b[c];
    v = tv;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j < a[i]; j++)
            upd[lower_bound(ALL(x), t[i][j] - t[i][j - 1]) - x.begin()]
                .push_back(t[i][j]);
    for (int i = 0; i < SZ(x); i++) {
        tv += (x[i] - lsx) * cnt * c, lsx = x[i], cnt -= SZ(upd[i]);
        for (int t : upd[i]) {
            tv -= b[mp[t]] * mp[t];
            mp[t]--, tv += b[mp[t]] * mp[t];
        }
        if (tv == v)
            ans.push_back(x[i]);
        else if (tv < v)
            v = tv, ans = {x[i]};
    }
    cout << v << ' ' << SZ(ans) << '\n';
    for (int i : ans) cout << i + 1 << ' ';
    cerr << clock() << '\n';
    return 0 ^ __ ^ 0;
}